package com.hlf.modules.merchant.order.controller;

import com.hlf.common.utils.PageUtils;
import com.hlf.common.utils.ReturnResult;
import com.hlf.modules.merchant.order.entity.OrderDetail;
import com.hlf.modules.merchant.order.service.OrderDetailService;
import com.hlf.modules.merchant.order.service.OrderService;
import com.hlf.modules.sys.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 订单
 * Created by Administrator on 2017/9/22.
 */

@RestController
@RequestMapping("/order")
public class OrderController extends AbstractController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetailService orderDetailService;

    /**
     * 订单列表
     */
    @RequestMapping("/list")
    public ReturnResult list(@RequestParam Map<String, Object> params) {

        Long userId = getUserId();
        params.put("userId", userId);
        PageUtils pageUtil = orderService.queryListForPage(params);

        return ReturnResult.ok().put("page", pageUtil);
    }


    /**
     * 订单详情
     */
    @RequestMapping("/detal/{id}")
    public ReturnResult list(@PathVariable(value = "id") String id) {
        List<OrderDetail> orderDetails = orderDetailService.selectDapthByOrderId(Long.parseLong(id));
        return ReturnResult.ok().put("orderDetails", orderDetails);
    }


}
